package com.kzd.sdk.core;

import android.app.Activity;

import java.util.ArrayList;
import java.util.List;

public class KZD_ActController {
    public static List<Activity> activities = new ArrayList<>();

    /**
     * 添加活动activity
     *
     * @param activity 活动
     */
    public static void addActivity(Activity activity) {
        activities.add(activity);
    }

    /**
     * 删除指定活动activity
     *
     * @param activity 活动
     */
    public static void removeActivity(Activity activity) {
        activities.remove(activity);

    }

    /**
     * 删除所有活动activity
     */
    public static void finishAll() {
        for (Activity activity : activities) {
            if (!activity.isFinishing()) {
                activity.finish();
            }
        }
        activities.clear();
    }
    /**
     * 删除所有其他活动activity
     */
    public static void finishOther(Activity now) {
        for (Activity activity : activities) {
            if(now!=activity)
                if (activity!=null&&!activity.isFinishing()) {
                    activity.finish();
                }
        }
        activities.clear();
        activities.add(now);
    }
}
